package games.ninJumpDx.tools
{
	import core.Global;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.media.Sound;
	
	import games.ninJumpDx.data.UIConfig;

	public class Tools
	{
		/*
		加载位图资源并生成位图对象
		*/
		public static function getBitmapByName(name:String,url:String):Bitmap
		{
			var bm:Bitmap = new Bitmap(getBitmapDataByName(name,url));
			return bm;
		}
		/*
		加载位图资源，返回位图数据对象
		*/
		public static function getBitmapDataByName(name:String,url:String):BitmapData
		{
			var link:String = UIConfig.getInfoByName(name).@linkName;
			if(link)
			{
				name = link;
			}
			var atom:* = Global.loadResource(url,name);
			var bmd:BitmapData = atom.obj;
			
			return bmd;
		}
		
		/*
		获取界面元素（通过其名称）的声音，
		*/
		public static function getSoundByUiName(name:String,url:String):Sound
		{
			var link:String = UIConfig.getInfoByName(name).@linkName;
			if(link)
			{
				name = link;
			}
			var atom:* = Global.loadResource(url,name);
			var bmd:Sound = atom.obj;
			
			return bmd;
		}
		/*
		直接通过声音连接名获取声音
		*/
		public static function getSoundByName(name:String,url:String):Sound
		{
			var atom:* = Global.loadResource(url,name);
			var bmd:Sound = atom.obj;
			return bmd;
		}
	}
}